package com.sakiko.controller;

import com.sakiko.pojo.User;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {

    @GetMapping
    public List<User> pageList(@RequestParam(value = "page", defaultValue = "1") int page,
                               @RequestParam(value = "size", defaultValue = "10") int size) {
        System.out.println("UserController.pageList");
        System.out.println("page = " + page + ", size = " + size);
        return null;
    }

    @PostMapping
    public User save(@RequestBody User user) {
        System.out.println("UserController.save");
        System.out.println("User = " + user);
        return user;
    }

    @GetMapping({"id"})
    public User detail(@PathVariable Integer id) {
        System.out.println("UserController.detail");
        System.out.println("id = " + id);
        return null;
    }

    @PutMapping
    public User update(@RequestBody User user) {
        System.out.println("UserController.update"); // soutm
        System.out.println("user = " + user); // soutp
        return user;
    }

    @DeleteMapping("{id}")
    public User delete(@PathVariable Integer id) {
        System.out.println("UserController.delete");
        System.out.println("id = " + id);
        return null;
    }

    @GetMapping("like") // 避免重复路径 (方法
    public User like(@RequestParam(defaultValue = "1") int page,
                     @RequestParam(defaultValue = "10") int size,
                     String keyword) {
        System.out.println("UserController.like");
        System.out.println("page = " + page + ", size = " + size + ", keyword = " + keyword);
        return null;
    }
}
